package uk.ac.glasgow.demosocs.impl.ui;

import uk.ac.glasgow.clui.CommandDescription;
import uk.ac.glasgow.clui.MinimumArguments;
import uk.ac.glasgow.clui.SystemCommand;
import uk.ac.glasgow.clui.SystemCommandException;
import uk.ac.glasgow.demosocs.Election;
import uk.ac.glasgow.demosocs.VotingSystem;
import uk.ac.glasgow.demosocs.impl.ElectionImpl;

@MinimumArguments(0)
@CommandDescription("Display electorate of current election.")
public class ViewElectorateCommand extends SystemCommand<VotingSystem> {

	public ViewElectorateCommand(VotingSystem facade) {
		super(facade);
	}

	@Override
	public String processCommand(String[] arguments) throws SystemCommandException {
		String guid = facade.getCurrentUserGUID();
		if (guid == null)
			throw new SystemCommandException("No current user set.");
			
		Election election = facade.getCurrentElection();
		ElectionImpl e = ((ElectionImpl) election);
		
		if (election == null)
			throw new SystemCommandException("No current election set.");
		
		String electorate = e.getElectorateID();
		return "Electorate for election "+ e.getEID() + " is " + electorate;
	}

}
